<div class="container">
	<ol class="breadcrumb">
		<li><?php echo anchor('', 'Início'); ?></li>
		<li><?php echo anchor('parasuaempresa', 'Para Sua Empresa'); ?></li>
		<li><?php echo anchor('parasuaempresa/cardapio', 'Cardápio'); ?></li>
		<li class="active"><?php echo $page_title; ?></li>
	</ol>
</div>

<div class="container">

	<div class="row">
		<?php $this->load->view('parasuaempresa/_sidebar'); ?>

		<div class="col-lg-9 col-md-9">			
			<h3 class="titulos"><?php echo $page_title; ?></h3>

			<?php
				if(!empty($formMessage)){
					$cssOptions = array('alert-danger', 'alert-warning', 'alert-success');
					$cssAlert = $cssOptions[$formMessage[0]-1];
			?>
			<div class="alert <?php echo $cssAlert; ?>">
				<?php echo $formMessage[1]; ?>
			</div>
			<?php
				}

				if(!empty($image_error)){
			?>
			<div class="alert alert-danger">
				<?php echo $image_error; ?>
			</div>
			<?php
				}
			?>

			<textarea id="templateTamanho" class="hidden">
				<tr>
					<td>
						<?php
							echo form_hidden('tamanho_item_cod_auto_{0}', '');
							$options = array(''=>'');
							echo form_dropdown('tamanho_cod_auto_{0}', $options, '', 'class="form-control"');
						?>
					</td>
					<td>
						<div class="input-group">
							<span class="input-group-addon">R$ </span>
							<?php 
								echo form_input(array('name'=>'tamanho_preco_{0}','class'=>'form-control')); 
							?>
						</div>
					</td>
					<td>
						<?php 
							echo form_input(array('name'=>'tamanho_peso_{0}','class'=>'form-control')); 
						?>							
					</td>
					<td>
						<?php 
							echo form_input(array('name'=>'tamanho_obs_{0}','class'=>'form-control')); 
						?>
					</td>
				</tr>
			</textarea>

			<?php 
				$hidden = array('datetime' => date('Ymdhmi'));
				$attributes = array("role"=>"form", "id"=>"form_item");
				echo form_open_multipart(current_url(), $attributes, $hidden);
			?>
			<div class="form-group">
				<div class="text-right">
					<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-default"> 
						<span class="glyphicon glyphicon-chevron-left"></span>	Voltar
					</a>

					<button type="submit" class="btn btn-primary">
						<span class="glyphicon glyphicon-ok-circle"></span> Salvar
					</button>
				</div>
			</div>

			<div class="row">
				<div class="col-md-3">
					<div class="form-group">
						<label for="categoria">Categoria</label>
						<?php
							$options = array();
							foreach($categorias as $cat){
								$options[$cat->getCodCategoria()] = $cat->getDescCategoria();
							}

							echo form_dropdown( 'categoria', 
												$options, 
												isset($formData['cod_categoria_auto']) ? $formData['cod_categoria_auto'] : 0, 
												'id="categoria" class="form-control"');
						?>						
					</div>
				</div>
				<div class="col-md-7">
					<div class="form-group">
						<label for="desc_item">Nome</label>
						<?php echo form_input(array('name'=>'desc_item','id'=>'desc_item','class'=>'form-control', 'value' => isset($formData['desc_item']) ? $formData['desc_item'] : '')); ?>
					</div>
				</div>
				<div class="col-md-2">
					<div class="form-group">
						<label for="ativo">Ativo?</label>
						<?php
							$options = array(0=>"Sim", 1=>"Não");
							echo form_dropdown( 'ativo', 
												$options, 
												isset($formData['item_indisponivel']) ? $formData['item_indisponivel'] : 0, 
												'id="ativo" class="form-control"');
						?>
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-md-12">
					<div class="form-group">
						<label for="obs_item">Descrição do produto</label>
						<?php echo form_textarea(array('name'=>'obs_item','id'=>'obs_item','class'=>'form-control', 'style'=>'height:80px', 'value' => isset($formData['obs']) ? $formData['obs'] : '')); ?>
					</div>
				</div>
			</div>

			<h4 class="titulos">Tamanhos</h4>
			
			<?php
				if(count($tamanhos) == 0){
			?>

			<div id="boxNovoTamanho" class="row">
				<div class="col-md-6 col-md-offset-3">
					<div class="input-group">					  	
					  	<span class="input-group-addon">Você ainda não cadastrou tamanhos.</span>
					  	<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-md btn-primary pull-right form-control btnNovoTamanho" data-toggle="modal" data-remote="false" data-target="#modalTamanho"> 
							<span class="glyphicon glyphicon-plus-sign"></span>	Novo Tamanho
						</a>
					</div>
				</div>
			</div>
			
			<?php
				}
			?>
			
			<div id="tabelaTamanho" <?php echo count($tamanhos) == 0 ? 'class="hidden"' : ''; ?>>
				<div class="table-responsive">
					<table class="table">
						<thead>
							<tr>
								<th style="width:130px">Tamanho</th>
								<th style="width:150px">Preço</th>
								<th style="width:150px">Peso</th>
								<th>Obs</th>
							</tr>
						</thead>
						<tbody>
							<?php 
								$options = array(""=>"");

								foreach($tamanhos as $tam){
									$options[$tam->getCodTamanhoAuto()] = $tam->getCodTamanho();
								}

								$tamsItem = $item->getTamanhos();

								if(count($tamsItem) == 0){
							?>
							<tr>
								<td>
									<?php
										echo form_hidden('tamanho_item_cod_auto_1', '');
										echo form_dropdown('tamanho_cod_auto_1', $options, '', 'class="form-control"');
									?>
								</td>
								<td>
									<div class="input-group">
		  								<span class="input-group-addon">R$ </span>
										<?php
											echo form_input(array('name'=>'tamanho_preco_1','class'=>'form-control')); 
										?>
									</div>
								</td>
								<td>
									<?php 
										echo form_input(array('name'=>'tamanho_peso_1','class'=>'form-control')); 
									?>							
								</td>
								<td>
									<?php 
										echo form_input(array('name'=>'tamanho_obs_1','class'=>'form-control')); 
									?>
								</td>
							</tr>
							<?php 
								}else{
									$counter  = 1;
									
									foreach($tamsItem as $tamItem){
							?>
								<tr>
									<td>
										<?php
											echo form_hidden('tamanho_item_cod_auto_'.$counter, $tamItem->getCodTamanhoItemAuto());
											echo form_dropdown('tamanho_cod_auto_'.$counter, $options, $tamItem->getCodTamanho(), 'class="form-control"');
										?>
									</td>
									<td>
										<div class="input-group">
			  								<span class="input-group-addon">R$ </span>
											<?php
												echo form_input(array('name'=>'tamanho_preco_'.$counter,'class'=>'form-control', 'value'=>$tamItem->getPreco())); 
											?>
										</div>
									</td>
									<td>
										<?php 
											echo form_input(array('name'=>'tamanho_peso_'.$counter,'class'=>'form-control', 'value'=>$tamItem->getPeso())); 
										?>							
									</td>
									<td>
										<?php 
											echo form_input(array('name'=>'tamanho_obs_'.$counter,'class'=>'form-control', 'value'=>$tamItem->getObs())); 
										?>
									</td>
								</tr>
							<?php 
										$counter++;
									}
								}
							?>
						</tbody>
					</table>
				</div>

				<div class="text-right">
					<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-sm btn-default btnAddTamanho"> 
						<span class="glyphicon glyphicon-plus-sign"></span>	Adicionar
					</a>

					<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-sm btn-primary btnNovoTamanho"> 
						<span class="glyphicon glyphicon-plus-sign"></span>	Novo Tamanho
					</a>
				</div>
			</div>
			
			<h4 class="titulos">Ingredientes adicionais</h4>

			<?php
				if(count($ingredientes) == 0){
			?>

			<div id="boxNovoIngrediente" class="row">
				<div class="col-md-6 col-md-offset-3">
					<div class="input-group">
						<span class="input-group-addon">Você ainda não cadastrou ingredientes.</span>

						<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-md btn-primary pull-right form-control btnNovoIngrediente" data-toggle="modal" data-remote="false" data-target="#modalIngrediente"> 
							<span class="glyphicon glyphicon-plus-sign"></span>	Novo Ingrediente
						</a>
					</div>
				</div>
			</div>

			<?php
				}

				$options  = array(""=>"");
				$ingr_itm = array("", "", "", "");

				foreach($ingredientes as $ingr){
					$options[$ingr->getCodIngrediente()] = $ingr->getDescIngrediente();
				}

				$ingredientes_item = $item->getIngredientes();

				if(count($ingredientes_item) > 0){
					for($i = 0; $i < count($ingredientes_item); $i++){
						$ingr_itm[$i] = $ingredientes_item[$i]->getCodIngrediente();
					}
				}

			?>

			<div id="tabelaIngredientes" <?php echo count($ingredientes) == 0 ? 'style="display:none"' : ''; ?>>
				
				<div class="table-responsive">
					<table class="table">
						<thead>
							<tr>
								<th>Adicional 1</th>
								<th>Adicional 2</th>
								<th>Adicional 3</th>
								<th>Adicional 4</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>
									<?php
										echo form_dropdown('cod_ingre_auto_1', $options, $ingr_itm[0], 'class="form-control"');
									?>
								</td>
								<td>
									<?php
										echo form_dropdown('cod_ingre_auto_2', $options, $ingr_itm[1], 'class="form-control"');
									?>
								</td>
								<td>
									<?php
										echo form_dropdown('cod_ingre_auto_3', $options, $ingr_itm[2], 'class="form-control"');
									?>
								</td>
								<td>
									<?php
										echo form_dropdown('cod_ingre_auto_4', $options, $ingr_itm[3], 'class="form-control"');
									?>
								</td>
							</tr>
						</tbody>
					</table>
				</div>

				<div class="text-right">
					<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-sm btn-primary btnNovoIngrediente"> 
						<span class="glyphicon glyphicon-plus-sign"></span>	Novo Ingrediente
					</a>
				</div>
			</div>

			<h4 class="titulos">Foto</h4>
			<div class="well well-sm">
				<div class="pull-right">
					<?php
						$foto = $item->getFoto();

						if(empty($foto)){
					?>
					<img src="<?php echo base_url('assets/images/sem-foto.png'); ?>" class="img-thumbnail" alt="Nenhuma imagem cadastarada" />
					<?php
						}else{
					?>
					<img src="<?php echo base_url('thumb.php?foto='.$item->getFoto().'&w=140&h=100&fx=140&fy=100'); ?>" class="img-thumbnail" />
					<?php
						}
					?>
				</div>

				<div class="form-group">
					<label for="foto">Escolha a foto</label>
					<input type="file" name="foto" id="foto">
					<span class="help-block">Foto deve ser PNG ou JPG, ter até 1024x768px e 1MB.</span>
				</div>

				<div class="clearfix"></div>
			</div>

			<div class="form-group">
				<div class="text-right">
					<a href="<?php echo site_url('parasuaempresa/cardapio'); ?>" class="btn btn-default"> 
						<span class="glyphicon glyphicon-chevron-left"></span>	Voltar
					</a>

					<button type="submit" class="btn btn-primary">
						<span class="glyphicon glyphicon-ok-circle"></span> Salvar
					</button>
				</div>
			</div>

			<?php
				echo form_close();
			?>
		</div>

	</div>
</div>

<!-- Detalhes Pedido -->
<div class="modal fade" id="modalTamanho" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">Cadastrar tamanho</h4>
			</div>

			<?php
			$hidden = array('datetime' => date('Ymdhmi'));
			$attributes = array("role"=>"form", "id"=>"form_tamanho");
			echo form_open('parasuaempresa/cardapio/cadastrar_tamanho', $attributes, $hidden); 
			echo form_hidden('url_tamanhos',site_url('parasuaempresa/cardapio/get_tamanhos'));
			?>
			<div class="modal-body">
				<div class="alert hidden">
				</div>
				
				<div class="row">
					<div class="col-md-3">
						<div class="form-group">
							<label for="abreviatura">Abreviatura</label>
							<?php echo form_input(array('name'=>'abreviatura','id'=>'abreviatura','class'=>'form-control', 'value' => '', 'maxlength'=>'15')); ?>
							<span class="help-block hp-sample">Ex: M</span>
						</div>
					</div>
					<div class="col-md-9">
						<div class="form-group">
							<label for="descricao">Descrição</label>
							<?php echo form_input(array('name'=>'descricao','id'=>'descricao','class'=>'form-control', 'value' => '')); ?>
							<span class="help-block hp-sample">Ex: Médio</span>
						</div>
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">
					Cancelar
				</button>
				<button type="submit" class="btn btn-primary">
					Salvar
				</button>
			</div>

			<?php
			echo form_close();
			?>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- Novo Ingrediente -->
<div class="modal fade" id="modalIngrediente" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">Cadastrar ingrediente</h4>
			</div>

			<?php
			$hidden = array('datetime' => date('Ymdhmi'));
			$attributes = array("role"=>"form", "id"=>"form_ingrediente");
			echo form_open('parasuaempresa/cardapio/cadastrar_ingrediente', $attributes, $hidden); 
			echo form_hidden('url_ingredientes',site_url('parasuaempresa/cardapio/get_ingredientes'));
			?>
			<div class="modal-body">
				<div class="alert hidden">
				</div>
				
				<div class="row">
					<div class="col-md-7">
						<div class="form-group">
							<label for="nome_ingrediente">Nome ingrediente</label>
							<?php echo form_input(array('name'=>'nome_ingrediente','id'=>'nome_ingrediente','class'=>'form-control', 'value' => '')); ?>
							
						</div>
					</div>
					<div class="col-md-5">
						<div class="form-group">
							<label for="preco_ingrediente">Preço</label>
							<div class="input-group">
		  						<span class="input-group-addon">R$ </span>
								<?php echo form_input(array('name'=>'preco_ingrediente','id'=>'preco_ingrediente','class'=>'form-control', 'value' => '')); ?>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">
					Cancelar
				</button>
				<button type="submit" class="btn btn-primary">
					Salvar
				</button>
			</div>

			<?php
			echo form_close();
			?>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->